package web;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.io.File;

/**
 * Created by taohj on 2014/12/19.
 */
@WebListener
public class MyServletContextListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {

        String realPath=servletContextEvent.getServletContext().getRealPath("/") + "upload";
        File dir=new File(realPath);

        File [] files=dir.listFiles();
        for (int i = 0; i <files.length ; i++) {
            files[i].delete();
        }

        System.out.println("contextInitialized");
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        System.out.println("contextDestroyed");
    }
}
